
package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import pojo.Activities;
import pojo.AccuracyLevels;

public class AccuracyLevelsDao

{
    String driverName = "com.mysql.jdbc.Driver";
    Connection con;
    public AccuracyLevelsDao()
    {
        try
        {
            Class.forName(driverName).newInstance();
            con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/dimensionproject", "root","root");
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
/////////////////////////////////////////Adding new Accuracy Level///////////////////////////////    
    public void add(AccuracyLevels aculevel)
    {
        try
        {
            PreparedStatement pstmt = con.prepareStatement("insert into accuracy_levels values(?,?,?,?,?,?,?,?,?)") ;
            pstmt.setInt(1,aculevel.getAlId());
            pstmt.setInt(2,aculevel.getWidthBy());
            pstmt.setInt(3,aculevel.getPagesBy());
            pstmt.setInt(4,aculevel.getDepthBy());
            pstmt.setInt(5,aculevel.getLengthBy());
            pstmt.setInt(6,aculevel.getWeightBy());
            pstmt.setInt(7,aculevel.getFormatBy());
            pstmt.setInt(8,aculevel.getMailFormatBy());
            pstmt.setInt(9,aculevel.getItemBy());
            pstmt.execute() ;
        }
        catch(SQLException ex1)
        {
            ex1.printStackTrace();
        }
    }
//////////////////////////////////////delete Accuracy Level/////////////////////////////////////////
    public void delete(AccuracyLevels aculevel)
    {
        try
        {
            PreparedStatement pstmt = con.prepareStatement("delete from accuracy_levels where al_id=?") ;
            pstmt.setInt(1,aculevel.getAlId());
            pstmt.execute() ;
        }
        catch(SQLException ex1)
        {
            ex1.printStackTrace();
        }
    }
//////////////////////////////////////update Accuracy Level//////////////////////////////////////////////////
    public void update(AccuracyLevels aculevel)
    {
        try 
        {
//            boolean first=false;
//            int updatetxt=0;
//            if(aculevel.getWidthBy()!= 0)
//            {   first=true;
//                updatetxt=aculevel.getWidthBy();
//            }
//            if(aculevel.getPagesBy()!=0)
//            {
//                if (first) {
//                    updatetxt+=0;
//                }
//                 first=true;
//                updatetxt+=aculevel.getPagesBy();
//            }
//            if(aculevel.getDepthBy()!=0)
//            {
//                  if (first) {
//                    updatetxt+=0;
//                }
//                   first=true;
//                updatetxt+=aculevel.getDepthBy();
//            }
//            if(aculevel.getLengthBy()!=0)
//            {
//                  if (first) {
//                    updatetxt+=0;
//                }
//                   first=true;
//                updatetxt+=aculevel.getLengthBy();
//            }
//            if(aculevel.getWeightBy()!=0)
//            {
//                  if (first) {
//                    updatetxt+=0;
//                }
//                   first=true;
//                updatetxt+=aculevel.getWeightBy();
//            }
//            if(aculevel.getFormatBy()!=0)
//            {
//                  if (first) {
//                    updatetxt+=0;
//                }
//                   first=true;
//                updatetxt+=aculevel.getFormatBy();
//            }
//            if(aculevel.getMailFormatBy()!=0)
//            {
//                  if (first) {
//                    updatetxt+=0;
//                }
//                   first=true;
//                updatetxt+=aculevel.getMailFormatBy();
//            }
//            if(aculevel.getItemBy()!=0)
//            {
//                  if (first) {
//                    updatetxt+=0;
//                }
//                   first=true;
//                updatetxt+=aculevel.getItemBy();
//            }
//        
            PreparedStatement ps=con.prepareStatement("update accuracy_levels set width_by=? , pages_by=? , depth_by=? , length_by=? , weight_by=? , format_by=? , mail_format_by=? , item_by=?  where al_id=?");
            ps.setInt(1, aculevel.getWidthBy());
            ps.setInt(2, aculevel.getPagesBy());
            ps.setInt(3, aculevel.getDepthBy());
            ps.setInt(4, aculevel.getLengthBy());
            ps.setInt(5, aculevel.getWeightBy());
            ps.setInt(6, aculevel.getFormatBy());
            ps.setInt(7, aculevel.getMailFormatBy());
            ps.setInt(8, aculevel.getItemBy());
            ps.setInt(9, aculevel.getAlId());
            ps.executeUpdate();
            
        } catch (SQLException ex) 
        {
            ex.printStackTrace();
        }
    
    }
    
}
